﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright file="DataColumnEqualityComparer.cs" company="">
//   
// </copyright>
// <summary>
//   The data column equality comparer.
// </summary>
// --------------------------------------------------------------------------------------------------------------------
namespace UITest.Helpers.TableCompare
{
    using System;
    using System.Collections.Generic;
    using System.Data;

    /// <summary>
    ///     The data column equality comparer.
    /// </summary>
    public class DataColumnEqualityComparer : IEqualityComparer<DataColumn>
    {
        #region Static Fields

        /// <summary>
        ///     The instance.
        /// </summary>
        public static DataColumnEqualityComparer Instance = new DataColumnEqualityComparer();

        #endregion

        #region Public Methods and Operators

        /// <summary>
        /// The equals.
        /// </summary>
        /// <param name="x">
        /// The x.
        /// </param>
        /// <param name="y">
        /// The y.
        /// </param>
        /// <returns>
        /// The <see cref="bool"/>.
        /// </returns>
        public bool Equals(DataColumn x, DataColumn y)
        {
            return string.Equals(x.ColumnName, y.ColumnName, StringComparison.OrdinalIgnoreCase)
                   && (x.DataType == y.DataType);
        }

        /// <summary>
        /// The get hash code.
        /// </summary>
        /// <param name="dataColumn">
        /// The data column.
        /// </param>
        /// <returns>
        /// The <see cref="int"/>.
        /// </returns>
        public int GetHashCode(DataColumn dataColumn)
        {
            return (dataColumn.ColumnName == null ? 0 : dataColumn.ColumnName.GetHashCode())
                   ^ (dataColumn.DataType == null ? 0 : dataColumn.DataType.GetHashCode());
        }

        #endregion
    }
}